package com.yanqu.road.dao.impl.mogulbirthday;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.mogulbirthday.MogulBirthDayInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class MogulBirthDayConfigDaoImpl extends TempDao {

    private static String getMogulBirthDayInfoSql = "select * from `t_s_mogul_birthday` ";
    public List<MogulBirthDayInfo> getMogulBirthDayInfoList() {
        List<MogulBirthDayInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getMogulBirthDayInfoSql);
            rs = call.executeQuery();
            while (rs.next()) {
                MogulBirthDayInfo data = new MogulBirthDayInfo();
                data.setServerId(rs.getLong("serverId"));
                data.setUserId(rs.getLong("userId"));
                data.setBirthDay(rs.getTimestamp("birthday"));
                data.setReward(rs.getString("reward"));
                data.setBlessReward(rs.getString("blessReward"));
                data.setPosterSwitch(rs.getInt("posterSwitch"));
                data.setCreateRoleTime(rs.getTimestamp("createRoleTime"));
                data.setPosterServerListStr(rs.getString("posterServerList"));
                data.setPosterServerList(StringUtils.stringToLongList(data.getPosterServerListStr(), ","));
                data.setBanquetServerListStr(rs.getString("banquetServerList"));
                data.setBanquetServerList(StringUtils.stringToLongList(data.getBanquetServerListStr(), ","));
                data.setRemark(rs.getString("remark"));
                list.add(data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }
}
